package com.botao.tip.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.botao.tip.entity.Department;
import com.botao.tip.service.DepartmentService;
import com.botao.tip.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @author : vip865047755@126.com
 * @version :JDK1.8
 * @date : 2020/12/2 22:52
 * @File : DepartmentController.java
 * @software: IntelliJ IDEA
 */
@RestController
@RequestMapping("/api/department/")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("query/all")
    public AjaxResult queryAll() {
        return AjaxResult.success(departmentService.queryAll());
    }

    @GetMapping("add/department")
    public AjaxResult addDepartmentService(String department) {
        if (departmentService.addDepartment(department) > 0) {
            return AjaxResult.success(department);
        } else {
            return AjaxResult.error("该部门已存在？");
        }
    }

    @DeleteMapping("delete/{departmentId}")
    public AjaxResult deleteDepartment(@PathVariable String departmentId) {
        return departmentService.remove(new QueryWrapper<Department>().eq("departmentId", departmentId)) ? AjaxResult.success() : AjaxResult.error();
    }
}
